package com.grape.demo_graphql.exceptions;

import graphql.GraphqlErrorException;
import graphql.kickstart.spring.error.ThrowableGraphQLError;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author robin
 * @Date 2021/11/2
 * @Description
 */
@Component
public class GraphqlExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public ThrowableGraphQLError handle(RuntimeException e){
        return new ThrowableGraphQLError(e,"run time exception");
    }
    @ExceptionHandler(GraphqlErrorException.class)
    public ThrowableGraphQLError handle(GraphqlErrorException e){
        return new ThrowableGraphQLError(e);
    }
}
